package com.esisa.business;

import java.util.List;

import com.esisa.dao.CompteDao;
import com.esisa.dao.CreteresVaccinantionDao;
import com.esisa.dao.MaladieDao;
import com.esisa.dao.MedicamentDao;
import com.esisa.dao.RaceDao;
import com.esisa.dao.VaccinationCatalogueDao;
import com.esisa.dao.VeterinaireDao;
import com.esisa.exceptions.UserAlreadyExistsException;
import com.esisa.models.Maladie;
import com.esisa.models.Medicament;
import com.esisa.models.Race;
import com.esisa.models.VaccinationCatalogue;
import com.esisa.models.Veterinaire;

public class DefaultVeterinaireManager implements VeterinaireManager {

	private VeterinaireDao veterinaireDao;
	private CompteDao compteDao;
	private MaladieDao maladieDao;
	private MedicamentDao medicamentDao;
	private VaccinationCatalogueDao vaccinationCatalogueDao;
	private CreteresVaccinantionDao creteresVaccinantionDao;
	private RaceDao raceDao;
	@Override
	public boolean create(Veterinaire veterinaire) {
			System.out.println(">>>DefaultVeterinaireManager.create();");
		try {
			veterinaireDao.insert(veterinaire);
			compteDao.insert(veterinaire.getCompte());
		} catch (UserAlreadyExistsException e) {
			return false;
		}
		return true;
	}	
	@Override
	public List<Veterinaire> findAll() {
		return veterinaireDao.selectAll();
	}
	@Override
	public void delete(Veterinaire veterinaire) {
		compteDao.delete(veterinaire.getCompte());
		veterinaireDao.delete(veterinaire);
	}
	@Override
	public Veterinaire find(Long idVeterinaire) {
		return veterinaireDao.select(idVeterinaire);
	}
	@Override
	public void update(Veterinaire veterinaire) {
		System.out.println(">>DefaultVeterinaireManager:Update");
		 veterinaireDao.update(veterinaire);
		
	}
	@Override
	public boolean createMaladie(Maladie maladie) 
	{
		return maladieDao.insert(maladie);
	}
	
	
	
	public void setVeterinaireDao(VeterinaireDao veterinaireDao) {
		this.veterinaireDao = veterinaireDao;
	}
	public void setCompteDao(CompteDao compteDao) {
		this.compteDao = compteDao;
	}
	public void setMedicamentDao(MedicamentDao medicamentDao) {
		this.medicamentDao = medicamentDao;
	}
	public void setMaladieDao(MaladieDao maladieDao) {
		this.maladieDao = maladieDao;
	}
	
	public void setRaceDao(RaceDao raceDao) {
		this.raceDao = raceDao;
	}
	
	public void setVaccinationCatalogueDao(
			VaccinationCatalogueDao vaccinationCatalogueDao) {
		this.vaccinationCatalogueDao = vaccinationCatalogueDao;
	}
	
	public void setCreteresVaccinantionDao(
			CreteresVaccinantionDao creteresVaccinantionDao) {
		this.creteresVaccinantionDao = creteresVaccinantionDao;
	}
	@Override
	public boolean createMedicament(Medicament medicament) {
		return medicamentDao.insert(medicament);
	}
	@Override
	public boolean createRace(Race race) {
			return raceDao.insert(race);
	}
	@Override
	public void createCatalogue(VaccinationCatalogue catalogue) {
		vaccinationCatalogueDao.insert(catalogue);
		creteresVaccinantionDao.insert(catalogue.getCreteresVaccinantion());
	
	}
	// alami
		@Override
		public List<Race> findAllRaces() {
			
			return raceDao.selectAll();
		}
		@Override
		public List<Race> FindRaceByType(String idType) {
			System.out.println("default veterinaire manager FindRaceSelonType" );
			return raceDao.selectRaceByType(idType);
		}
		@Override
		public List<Medicament> findAllMedicaments() {
			return medicamentDao.selectAll();
		}
		@Override
		public Medicament findMedicament(String nom) {
			return medicamentDao.select(nom);
		}
		@Override
		public VaccinationCatalogue findCatalogue(Long id) {
			return vaccinationCatalogueDao.select(id);
		}
		@Override
		public void updateCatalogue(VaccinationCatalogue catalogue) {
			 vaccinationCatalogueDao.update(catalogue);
			
		}
		@Override
		public List<Maladie> findAllMaladies() {
			return maladieDao.selectAll();
		}
	
}
